<?php


namespace app\common\service\live;


use AlibabaCloud\SDK\Ocr\V20191230\Models\RecognizeIdentityCardRequest;
use AlibabaCloud\SDK\Ocr\V20191230\Ocr;
use app\common\service\BaseService;
use Darabonba\OpenApi\Models\Config;

class LiveHostService extends BaseService
{
    /**
     * 使用AK&SK初始账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Ocr Client
     */
    public static function createClient($accessKeyId, $accessKeySecret)
    {
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => \config("setting.aliyun.accessKeyId"),
            // 您的AccessKey Secret
            "accessKeySecret" => \config("setting.aliyun.accessKeySecret")
        ]);
        // 访问的域名
        $config->endpoint = "ocr.cn-shanghai.aliyuncs.com";
        return new Ocr($config);
    }


    /**
     * Author:YangXinPeng
     * 进行OCR身份证识别
     * @param $args
     * @return array
     */
    public static function main($args)
    {
        $client = self::createClient("accessKeyId", "accessKeySecret");
        $recognizeIdentityCardRequest = new RecognizeIdentityCardRequest([
            "imageURL" => $args['img'],
            "side" => $args['side']
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $body = $client->recognizeIdentityCard($recognizeIdentityCardRequest);
        $data = $body->body->data;
        return self::success('成功', $data);

    }
}